package behavioralPattern.strategy.example03;

import behavioralPattern.strategy.example02.Receipt;
import lombok.Data;

/**
 * 上下文类，持有策略接口，决定使用哪个策略
 */
public class Conetxt {

    // 维护抽象策略对象
    private ReceiptHandlerStrategy receiptHandlerStrategy;

    public Conetxt() {

    }

    // 调用具体策略
    public void handlerReceipt(Receipt receipt){
        if (receipt == null){
            System.out.println("不能为空！");
        }
        receiptHandlerStrategy.handleReceipt(receipt);
    }

    public ReceiptHandlerStrategy getReceiptHandlerStrategy() {
        return receiptHandlerStrategy;
    }

    public void setReceiptHandlerStrategy(ReceiptHandlerStrategy receiptHandlerStrategy) {
        this.receiptHandlerStrategy = receiptHandlerStrategy;
    }
}
